// remarkWrite.js
var app = getApp(); 
var utils=require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentTab:0,
    teamId :0,
    studentId :0,
    content : "",
    studentNo: 0,
    studentName: "",
    remarkRecordList:[],
    remarkWriteData: {
      placeholderTxt: "请输入评语内容",
      gtBtnTxt: "发布"
    },
    content : ""
  },
  remarkTap: function (e) {
    console.log(e.currentTarget.dataset.id);
    this.setData({
      currentTab: e.currentTarget.dataset.id
    });
  },
 
  /** 
   * 评语发布
   */
  formSubmit: function(e){
    var that = this;
    //var content = that.data.content;
    var content = e.detail.value.textarea;
    var teamId = that.data.teamId;
    var studentId = that.data.studentId;
    console.log("评语发布content==", content);
    console.log("评语发布teamId==", teamId);
    console.log("评语发布studentId==", studentId);
    wx.request({
      url: app.globalData.http + "addComments.do",
      header: {
        'content-type': 'application/json'
      },
      data: {
        teamId : teamId ,
        studentId: studentId,
        content: content,
        busId: parseInt(wx.getStorageSync("busId")),
        employeesId: parseInt(wx.getStorageSync("employeesId")),
        schoolId: parseInt(wx.getStorageSync("schoolId"))
      },
      success: function(res){
        console.log("评语发布成功返回数据==",res);
        var code = res.data.code;
        if(code == 100){
          if(content == "" || content == null){
            wx.showToast({
              title: '不能为空',
              image: "/img/ico/fail.png",
              duration: 2000  
            });
            console.log("提交内容为空==")
            return false;
          } else{
            wx.redirectTo({
              url: "/pages/remarkSuccess/remarkSuccess"
            })
          } 
        }else{
          wx.showToast({
            title: '发布失败',
            image: "/img/ico/fail.png",
            duration: 2000  
          });
          return
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    console.log("新增评语==",options);
    that.setData({
      teamId: parseInt(options.teamId),
      studentId: parseInt(options.studentId),
      studentNo: options.studentNo,
      studentName: options.studentName
    });
    wx.setNavigationBarTitle({
      title: that.data.studentNo +"  " + that.data.studentName
    })
    wx.request({
      url: app.globalData.http + "selectCommentsByStudentId.do",
      header: {
        'content-type': 'application/json'
      },
      data: {
        teamId: parseInt(options.teamId),
        studentId: parseInt(options.studentId), 
        busId: parseInt(wx.getStorageSync("busId")),
        employeesId: parseInt(wx.getStorageSync("employeesId")),
        schoolId: parseInt(wx.getStorageSync("schoolId"))
      },
      success: function(res){
        console.log("新增评语--评语记录返回数据==",res.data);
        var code = res.data.code;
        if(code == 100){
          var list = res.data.data;
          var length = res.data.data.length;
          for(var i = 0; i < length; i++){
            list[i].updateDate = utils.formatTime( new Date(list[i].updateDate ));
          }
          that.setData({
            remarkRecordList: res.data.data
          });  
        }
        if(code == 200){
          that.setData({
            codeTxt: "暂无数据"
          })
        }
        if(code == 300){
          that.setData({
            codeTxt: "哇哦~接口异常"
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})